import Flutter
import UIKit

public class UpgradePlugin: NSObject, FlutterPlugin {
  public static func register(with registrar: FlutterPluginRegistrar) {
    let channel = FlutterMethodChannel(name: "upgrade", binaryMessenger: registrar.messenger())
    let instance = UpgradePlugin()
    registrar.addMethodCallDelegate(instance, channel: channel)
  }

  public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {

   switch call.method {
          case "getVersionInfo":
               let infoDictionary : [String : Any] = Bundle.main.infoDictionary!
                       let appName : Any = infoDictionary["CFBundleDisplayName"] // 程序名称
                       let mainVersion : Any = infoDictionary["CFBundleShortVersionString"] as Any // 主程序版本号
                       let minorVersion : Any = infoDictionary["CFBundleVersion"] as Any // 版本号(内部标示)
                       let appVersion = mainVersion as! String
                       let versionCode = minorVersion as! String
                       result(["versionName":appVersion,"versionCode":versionCode])
          case "getPlatformVersion":
               result("iOS " + UIDevice.current.systemVersion)
          case "install":
               result("iOS " + UIDevice.current.systemVersion)
          default:
              result(FlutterMethodNotImplemented)
          }
  }
}
